import React, { Component } from 'react'
import axios from 'axios'

export default class App extends Component {
  getStudents = () => {
    // 需要写成项目开启的端口号
    axios.get('http://localhost:3001/api1/students')
      .then(
        response => {console.log('成功了', response.data);},
        error => {console.log('失败了', error);}
      )
  }
  
  getCars = () => {
    // 需要写成项目开启的端口号
    axios.get('http://localhost:3001/api2/cars')
      .then(
        response => {console.log('成功了', response.data);},
        error => {console.log('失败了', error);}
      )
  }

  render() {
    return (
      <div>
        <button onClick={this.getStudents}>点击获取学生信息</button>
        <button onClick={this.getCars}>点击获取汽车信息</button>
      </div>
    )
  }
}
